/*
 * // Bristleback plugin - Copyright (c) 2010 bristleback.googlecode.com
 * // ---------------------------------------------------------------------------
 * // This program is free software; you can redistribute it and/or modify it
 * // under the terms of the GNU Lesser General Public License as published by the
 * // Free Software Foundation; either version 3 of the License, or (at your
 * // option) any later version.
 * // This library is distributed in the hope that it will be useful,
 * // but without any warranty; without even the implied warranty of merchantability
 * // or fitness for a particular purpose.
 * // You should have received a copy of the GNU Lesser General Public License along
 * // with this program; if not, see <http://www.gnu.org/licenses/lgpl.html>.
 * // ---------------------------------------------------------------------------
 */

package pl.bristleback.server.bristle.binding;

import org.apache.log4j.Logger;

/**
 * Wrapper class containing information about error while binding operation.
 * <p/>
 * Created on: 2011-02-27 17:00:32 <br/>
 *
 * @author Wojciech Niemiec
 */
public class BindingError {
  private static Logger log = Logger.getLogger(BindingError.class.getName());

  private BindingErrorType errorType;
  private String fieldName;

  /**
   * Creates and returns new binding error object with type
   * {@link pl.bristleback.server.bristle.binding.BindingErrorType#TYPE_MISMATCH} and given field name.
   * This error should be added when {@link pl.bristleback.server.bristle.binding.resolvers.PropertyValueResolver} cannot
   * extract object value properly and returns null.
   *
   * @param fieldName name of the field related with this type mismatch error.
   * @return type mismatch binding error.
   */
  public static BindingError addTypeMismatchError(String fieldName) {
    return addError(fieldName, BindingErrorType.TYPE_MISMATCH);
  }

  /**
   * Creates and returns new binding error object with type
   * {@link pl.bristleback.server.bristle.binding.BindingErrorType#NOT_NULL_VIOLATION} and given field name.
   * This 
   *
   * @param fieldName name of the field related with this not null error.
   * @return not null violation binding error.
   */
  public static BindingError addNotNullViolationError(String fieldName) {
    return addError(fieldName, BindingErrorType.NOT_NULL_VIOLATION);
  }

  private static BindingError addError(String fieldName, BindingErrorType errorType) {
    BindingError error = new BindingError();
    error.fieldName = fieldName;
    error.errorType = errorType;
    return error;
  }

  public String getFieldName() {
    return fieldName;
  }

  public BindingErrorType getErrorType() {
    return errorType;
  }
}
